<template>
  <div style="width:100wh;height:100vh" class="example">
    <a-spin size="large" :spinning="spinning" v-if="spinning" />
    <div style="font-Size:18px" v-else>用户未注册，请联系管理员</div>
    <!-- 授权页面 -->
  </div>
</template>

<script>
import { logout } from '@/api/loginout'
import { getUrlParams } from '@/utils/mUtils'
import { getCurrentUser } from '@/api/user'
import { mapActions, mapGetters } from 'vuex'
import longtan from '@/assets/homeImg/longtan.jpg'
import jiangyin from '@/assets/homeImg/jiangyin.jpg'
import axios from '@/utils/request'
export default {
  data() {
    return {
      ticket: getUrlParams().ticket,
      role: '',
      longtan,
      jiangyin,
      spinning: true
    }
  },
  mounted() {
    if (this.ticket) {
      this.getTickerLogin()
    } else {
      this.getUser()
    }
    // this.userInfo.roleList.forEach((item) => {
    //   switch (item) {
    //     case 'jg':
    //       this.role = item

    //       break
    //     case 'zhb':
    //       this.role = item

    //       break
    //     case 'jl':
    //       this.role = item

    //       break
    //     case 'sg':
    //       this.role = item
    //       break
    //     default:
    //       break
    //   }
    // })
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  methods: {
    ...mapActions(['getTicker']),

    async getTickerLogin() {
      // console.log(11111111111111111111);

      const result = await this.getTicker({ ticket: this.ticket })

      // console.log(data)
      // console.log(typeof res);

      // console.log(33333333333)
      if (typeof result == 'object') {
        let data = result.data
        if (data.code == '200') {
          console.log(data.data.projectId)
          let url = ''
          if (data.data.menuVOList.length > 0) {
            if (data.data.menuVOList[0].leafNode) {
              url = data.data.menuVOList[0].url
            } else {
              url = data.data.menuVOList[0].children[0].url
            }
          }

          data.data.roleList.forEach((item) => {
            switch (item) {
              case 'jg':
                this.role = item

                break
              case 'zhb':
                this.role = item

                break
              case 'jl':
                this.role = item

                break
              case 'sg':
                this.role = item
                break
              default:
                break
            }
          })
          let f = false
          let t = true
          switch (data.data.projectFullName) {
            case '沪陕高速公路平潮至广陵段扩建工程项目':
              sessionStorage.setItem(
                'imgdata',
                JSON.stringify({
                  img_content:
                    'https://lw-sit.oss-cn-beijing.aliyuncs.com/lw/RBvc-upload-1621479143274-10/1622109999533葛市互通.jpg',
                  detail: data.data.projectFullName,
                  fullName: data.data.projectFullName,
                  briefName: data.data.projectBriefName
                })
              )
              break

            default:
              sessionStorage.setItem(
                'imgdata',
                JSON.stringify({
                  img_content:
                    'https://fbzh-wage.oss-cn-hangzhou.aliyuncs.com/lw/RBvc-upload-1621479143274-10/1625812218993京沪.png',
                  detail: data.data.projectFullName,
                  fullName: data.data.projectFullName,
                  briefName: data.data.projectBriefName
                })
              )
              break
          }
          if (this.role == 'jg') {
            sessionStorage.setItem('homeFlag', t)
            window.location.replace(window.location.origin + window.location.pathname + '/#/gateway')
          } else if (this.role == 'zhb') {
            sessionStorage.setItem('projectId', data.data.projectId)
            sessionStorage.setItem('projectFlag', t)
            sessionStorage.setItem('homeFlag', f)
            window.location.replace(window.location.origin + window.location.pathname + '/#/projectDetails')
          } else if (this.role == 'jl') {
            sessionStorage.setItem('projectId', data.data.projectId)
            sessionStorage.setItem('projectFlag', t)
            sessionStorage.setItem('homeFlag', f)
            window.location.replace(window.location.origin + window.location.pathname + '/#/projectDetails')
          } else if (this.role == 'sg') {
            sessionStorage.setItem('projectId', data.data.projectId)
            sessionStorage.setItem('gatewayId', data.data.orgId)
            // sessionStorage.setItem('laborName', this.userInfo.projectFullName)
            sessionStorage.setItem('homeFlag', f)
            sessionStorage.setItem('projectFlag', f)
            window.location.replace(window.location.origin + window.location.pathname + `/#${url}`)
          } else {
            window.location.replace(window.location.origin + window.location.pathname + `/#${url}`)
          }
        }
      } else {
        // console.log(444444444444)
        this.spinning = false
        setTimeout(() => {
          logout({}).then((res) => {
            this.$message.success('退出成功')
            top.window.location =
              process.env.VUE_APP_CAS_URL + '/logout?service=' + encodeURIComponent(process.env.VUE_APP_PUBLIC_URL)
          })
        }, 2000)
      }
    },
    getUser() {
      //  axios({
      //       url: `/v1/auth/getCurrentUser`,
      //       method: "post",
      //       data:{},
      //     })
      //       .then((res) => {
      //         // console.log(res);
      //         this.dialogFormVisible = false;
      //         this.$message({
      //           message: "编辑成功",
      //           type: "success",
      //         });
      //         this.tableList();
      //       })
      //       .catch((err) => {});
      getCurrentUser().then((res) => {
        if (res) {
          console.log(this.userInfo.projectId)
          let url = ''
          if (this.userInfo.menuVOList.length > 0) {
            if (this.userInfo.menuVOList[0].leafNode) {
              url = this.userInfo.menuVOList[0].url
            } else {
              url = this.userInfo.menuVOList[0].children[0].url
            }
          }

          this.userInfo.roleList.forEach((item) => {
            switch (item) {
              case 'jg':
                this.role = item

                break
              case 'zhb':
                this.role = item

                break
              case 'jl':
                this.role = item

                break
              case 'sg':
                this.role = item
                break
              default:
                break
            }
          })
          let f = false
          let t = true

          switch (this.userInfo.projectFullName) {
            case '沪陕高速公路平潮至广陵段扩建工程项目':
              sessionStorage.setItem(
                'imgdata',
                JSON.stringify({
                  img_content:
                    'https://lw-sit.oss-cn-beijing.aliyuncs.com/lw/RBvc-upload-1621479143274-10/1622109999533葛市互通.jpg',
                  detail: this.userInfo.projectFullName,
                  fullName: this.userInfo.projectFullName,
                  briefName: this.userInfo.projectBriefName
                })
              )
              break

            default:
              sessionStorage.setItem(
                'imgdata',
                JSON.stringify({
                  img_content:
                    'https://fbzh-wage.oss-cn-hangzhou.aliyuncs.com/lw/RBvc-upload-1621479143274-10/1625812218993京沪.png',
                  detail: this.userInfo.projectFullName,
                  fullName: this.userInfo.projectFullName,
                  briefName: this.userInfo.projectBriefName
                })
              )
              break
          }
          if (this.role == 'jg') {
            sessionStorage.setItem('homeFlag', t)
            sessionStorage.setItem('projectFlag', t)
            window.location.replace(window.location.origin + window.location.pathname + '/#/gateway')
          } else if (this.role == 'zhb') {
            sessionStorage.setItem('projectId', this.userInfo.projectId)
            sessionStorage.setItem('projectFlag', t)
            sessionStorage.setItem('homeFlag', f)
            window.location.replace(window.location.origin + window.location.pathname + '/#/projectDetails')
          } else if (this.role == 'jl') {
            sessionStorage.setItem('projectId', this.userInfo.projectId)
            sessionStorage.setItem('projectFlag', t)
            sessionStorage.setItem('homeFlag', f)
            window.location.replace(window.location.origin + window.location.pathname + '/#/projectDetails')
          } else if (this.role == 'sg') {
            sessionStorage.setItem('projectId', this.userInfo.projectId)
            sessionStorage.setItem('gatewayId', this.userInfo.orgId)
            // sessionStorage.setItem('laborName', this.userInfo.projectFullName)
            sessionStorage.setItem('homeFlag', f)
            sessionStorage.setItem('projectFlag', f)
            if (this.userInfo.userName != 'lwgz')
              window.location.replace(window.location.origin + window.location.pathname + `/#${url}`)
            else {
              window.location.replace(window.location.origin + window.location.pathname + `/#${url}`)
            }
          } else {
            if (this.userInfo.userName != 'lwgz')
              window.location.replace(window.location.origin + window.location.pathname + `/#${url}`)
            else {
              window.location.replace(window.location.origin + window.location.pathname + `/#${url}`)
            }
          }
        } else {
          console.log(111)
          this.spinning = false
          setTimeout(() => {
            logout({}).then((res) => {
              this.$message.success('退出成功')
              top.window.location =
                process.env.VUE_APP_CAS_URL + '/logout?service=' + encodeURIComponent(process.env.VUE_APP_PUBLIC_URL)
            })
          }, 3000)
        }
      })
    }
  }
}
</script>

<style scoped>
.example {
  /* text-align: center; */
  background: rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  /* border-radius: 4px; */
  /* margin-bottom: 20px; */
  /* padding: 30px 50px;
  margin: 20px 0; */
}
</style>
